/**
 * Copyright 2013 ABSir's Studio
 * 
 * All right reserved
 *
 * Create on 2013-6-17 上午11:34:15
 */
package com.absir.bean.core;

import java.lang.reflect.Constructor;

import com.absir.bean.basis.BeanDefine;
import com.absir.bean.basis.BeanDefineMerge;
import com.absir.bean.basis.BeanFactory;
import com.absir.bean.basis.BeanScope;

/**
 * @author absir
 * 
 */
public class BeanDefineWrapper implements BeanDefine, BeanDefineMerge {

	/** beanDefine */
	protected BeanDefine beanDefine;

	/**
	 * @param beanDefine
	 */
	public BeanDefineWrapper(BeanDefine beanDefine) {
		this.beanDefine = beanDefine;
	}

	/**
	 * @return
	 */
	public BeanDefine getBeanDefine() {
		return beanDefine;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.absir.android.bean.value.IBeanDefine#getBeanType()
	 */
	@Override
	public Class<?> getBeanType() {
		// TODO Auto-generated method stub
		return beanDefine.getBeanType();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.absir.android.bean.value.IBeanDefine#getBeanName()
	 */
	@Override
	public String getBeanName() {
		// TODO Auto-generated method stub
		return beanDefine.getBeanName();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.absir.android.bean.value.IBeanDefine#getBeanObject()
	 */
	@Override
	public Object getBeanObject() {
		// TODO Auto-generated method stub
		return beanDefine.getBeanObject();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.absir.android.bean.value.IBeanDefine#getBeanScope()
	 */
	@Override
	public BeanScope getBeanScope() {
		// TODO Auto-generated method stub
		return beanDefine.getBeanScope();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.absir.android.bean.value.IBeanDefine#getBeanComponent()
	 */
	@Override
	public Object getBeanComponent() {
		// TODO Auto-generated method stub
		Object component = beanDefine.getBeanComponent();
		return component == null || (getBeanScope() != BeanScope.PROTOTYPE && component instanceof Constructor) ? null
				: component;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.absir.bean.basis.BeanDefine#getBeanFactory()
	 */
	@Override
	public BeanFactory getBeanFactory() {
		// TODO Auto-generated method stub
		return beanDefine.getBeanFactory();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.absir.android.bean.value.IBeanDefineWrapper#getBeanDefine(com.absir
	 * .android.bean.value.IBeanDefine)
	 */
	@Override
	public BeanDefine mergeBeanDefine(BeanDefine beanDefine) {
		// TODO Auto-generated method stub
		if (getBeanScope() == BeanScope.SINGLETON) {
			return new BeanDefineSingleton(getBeanName(), beanDefine.getBeanObject());

		} else if (getBeanScope() == BeanScope.SOFTREFERENCE) {
			return new BeanDefineSoftReference(getBeanName(), beanDefine.getBeanObject());
		}

		return this;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return beanDefine.hashCode();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		return beanDefine.equals(obj);
	}
}
